package com.xt.arrayList;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * 菜品操作类: 负责上架和浏览功能的实现;
 */
public class FoodOperator {
    // 1. 定义一个ArrayList集合对象
    private ArrayList<Food> foodList = new ArrayList<>();

    // 2. 开发功能: 上架菜品功能
    public void addFood() {
        // 3. 创建一个菜品对象, 封装上架的菜品信息
        Food food = new Food();

        // 4. 录入菜品信息
        Scanner scanner = new Scanner(System.in);
        System.out.println("请您输入该菜品名称");
        food.setName(scanner.next());

        System.out.println("请您输入该菜品价格");
        food.setPrice(scanner.nextDouble());

        System.out.println("请您输入该菜品介绍");
        food.setDescription(scanner.next());

        // 5. 把菜品对象存入到集合中去
        foodList.add(food);
        System.out.println("上架成功");
    }

    // 6. 展示菜品
    public void showAllFoods() {
        if (this.foodList.isEmpty()) {
            System.out.println("还没有菜品, 快去上架哦");
            return;
        }
        for (int i = 0; i < this.foodList.size(); i++) {
            Food temp = this.foodList.get(i);
            System.out.println(temp.getName());
            System.out.println(temp.getPrice());
            System.out.println(temp.getDescription());
            System.out.println("------------------------");
        }
    }

    // 负责展示操作界面
    public void start() {
        while (true) {
            System.out.println("请选择功能");
            System.out.println("1, 上架菜品");
            System.out.println("2, 查看菜品");
            System.out.println("3, 退出");
            Scanner scanner = new Scanner(System.in);
            int choice = scanner.nextInt();
            switch (choice) {
                case 1:
                    addFood();
                    break;
                case 2:
                    showAllFoods();
                    break;
                case 3:
                    System.out.println("快滚");
                    return;
                default:
                    System.out.println("您输入的命令不存在");
            }
        }

    }
}
